package com.sanyang.pda.ui.random;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sanyang.pda.adapter.ToBeStoredAdapter;
import com.sanyang.pda.bean.ToBeStoredBean;
import com.sanyang.pda.contract.ToBeStoredContract;
import com.sanyang.pda.presenter.ToBeStoredPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;
import com.wangshen.projectbase.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ToBeStoredFragment extends BaseMvpFragment<ToBeStoredPresenter> implements ToBeStoredContract.View, OnRefreshListener {
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    ToBeStoredAdapter adapter;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    private String en;

    public ToBeStoredFragment() {
    }

    public ToBeStoredFragment(String en) {
        this.en = en;
    }

    @Override
    public ToBeStoredPresenter getPresenter() {
        return new ToBeStoredPresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        smart.setEnableRefresh(true);
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        rvList.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new ToBeStoredAdapter(R.layout.item_tobe_store, new ArrayList<>());
        rvList.setAdapter(adapter);
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {
        smart.autoRefresh();

    }

    @Override
    public void setList(List<ToBeStoredBean> list) {
        smart.finishRefresh();
        adapter.setNewInstance(list);
    }

    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.finishRefresh();
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.samplingResultList(en);
    }
}
